package cn.wetcland.es.controller;

import cn.wetcland.es.config.exception.CustomerException;
import cn.wetcland.es.dto.ClassUpdateDTO;
import cn.wetcland.es.dto.GroupAddDTO;
import cn.wetcland.es.dto.StudentAddDTO;
import cn.wetcland.es.service.EsClassService;
import cn.wetcland.es.service.EsGroupService;
import cn.wetcland.es.service.EsStudentService;
import cn.wetcland.es.utils.MyAssert;
import cn.wetcland.es.vo.ExceptionVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manageClass")
public class ManageClassController {

    @Resource
    private EsStudentService studentService;

    @Resource
    private EsClassService classService;

    @Resource
    private EsGroupService groupService;

    @RequestMapping("/addClass")
    public String addClass(String className, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        classService.addNewClass(className);
        return "redirect:/manageClass?curPage=1&pageSize=6";
    }

    @RequestMapping("/deleteClass")
    public String deleteClass(Long classId, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        classService.deleteClass(classId);
        return "redirect:/manageClass?curPage=1&pageSize=6";
    }

    @RequestMapping("/updateClass")
    public String updateClass(ClassUpdateDTO classUpdateDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        classService.updateClass(classUpdateDTO);
        return "redirect:/manageClass?curPage=1&pageSize=6";
    }

    @RequestMapping("/addStudent")
    public String addStudent(StudentAddDTO studentAddDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        studentService.addNewStudent(studentAddDTO);
        return "redirect:/manageClass?curPage=1&pageSize=6";
    }

    @RequestMapping("/addGroup")
    public String addGroup(GroupAddDTO groupAddDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        groupService.addNewGroup(groupAddDTO);
        return "redirect:/manageClass?curPage=1&pageSize=6";
    }

}
